package model;

/**
 * this is a test class that checks the hand ranking methods from the hand class. 
 */
public class HandTest {
	
	public static void main(String[] args) {
		
		//Test the algorithm on a random hand
		Hand random = randomHand();
		System.out.println("Unsorted random hand \n"+random);
		
		random.sortHand(random.getHand());
		System.out.println("\nSorted \n"+random);
		
		random.determineHandRanking();
				
		System.out.println("\nThe random hand is "+random.rankingString()+"\n\n");
		System.out.println("\n-------------------------------------------------");
		
		//Test for Royal Flush
		Hand RF = new Hand();
		RF.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.HEARTS));
		RF.addCard(new Card(Card.CardRankEnum.KING,Card.CardSuitEnum.HEARTS));
		RF.addCard(new Card(Card.CardRankEnum.QUEEN,Card.CardSuitEnum.HEARTS));
		RF.addCard(new Card(Card.CardRankEnum.JACK,Card.CardSuitEnum.HEARTS));
		RF.addCard(new Card(Card.CardRankEnum.TEN,Card.CardSuitEnum.HEARTS));
		System.out.print("Should be 10 14 13 12 11 10: ");
		printArray(RF.determineHandRanking());
		
		//Test for Straight Flush
		Hand SF = new Hand();
		SF.addCard(new Card(Card.CardRankEnum.QUEEN,Card.CardSuitEnum.HEARTS));
		SF.addCard(new Card(Card.CardRankEnum.JACK,Card.CardSuitEnum.HEARTS));
		SF.addCard(new Card(Card.CardRankEnum.NINE,Card.CardSuitEnum.HEARTS));
		SF.addCard(new Card(Card.CardRankEnum.TEN,Card.CardSuitEnum.HEARTS));
		SF.addCard(new Card(Card.CardRankEnum.EIGHT,Card.CardSuitEnum.HEARTS));
		System.out.print("Should be 9 12 11 10 9 8: ");
		printArray(SF.determineHandRanking());
		
		//Test for Quadruple
		Hand QU = new Hand();
		QU.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.SPADES));
		QU.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.HEARTS));
		QU.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.DIAMONDS));
		QU.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.CLUBS));
		QU.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.HEARTS));
		System.out.print("Should be 8 5 14 0 0 0: ");
		printArray(QU.determineHandRanking());
		
		//Test for Full House
		Hand FH = new Hand();
		FH.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.SPADES));
		FH.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.HEARTS));
		FH.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.DIAMONDS));
		FH.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.CLUBS));
		FH.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.HEARTS));
		System.out.print("Should be 7 7 3 0 0 0: ");
		printArray(FH.determineHandRanking());
		
		//Test for Flush
		Hand FL = new Hand();
		FL.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.SPADES));
		FL.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.SPADES));
		FL.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.SPADES));
		FL.addCard(new Card(Card.CardRankEnum.NINE,Card.CardSuitEnum.SPADES));
		FL.addCard(new Card(Card.CardRankEnum.QUEEN,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 6 12 9 7 5 3: ");
		printArray(FL.determineHandRanking());
		
		//Test for Straight
		Hand ST = new Hand();
		ST.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.SPADES));
		ST.addCard(new Card(Card.CardRankEnum.SIX,Card.CardSuitEnum.HEARTS));
		ST.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.SPADES));
		ST.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.DIAMONDS));
		ST.addCard(new Card(Card.CardRankEnum.FOUR,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 5 7 6 5 4 3: ");
		printArray(ST.determineHandRanking());
		
		//Test for STRAIGHT WITH AN ACE
		Hand STA = new Hand();
		STA.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.SPADES));
		STA.addCard(new Card(Card.CardRankEnum.DEUCE,Card.CardSuitEnum.HEARTS));
		STA.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.SPADES));
		STA.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.DIAMONDS));
		STA.addCard(new Card(Card.CardRankEnum.FOUR,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 5 5 4 3 2 1: ");
		printArray(STA.determineHandRanking());
		
		//Test for Triple
		Hand TE = new Hand();
		TE.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.SPADES));
		TE.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.HEARTS));
		TE.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.SPADES));
		TE.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.DIAMONDS));
		TE.addCard(new Card(Card.CardRankEnum.FOUR,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 4 14 5 4 0 0: ");
		printArray(TE.determineHandRanking());
		
		//Test for Two Pair
		Hand TP = new Hand();
		TP.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.SPADES));
		TP.addCard(new Card(Card.CardRankEnum.ACE,Card.CardSuitEnum.HEARTS));
		TP.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.SPADES));
		TP.addCard(new Card(Card.CardRankEnum.FIVE,Card.CardSuitEnum.DIAMONDS));
		TP.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 3 14 5 7 0 0: ");
		printArray(TP.determineHandRanking());
		
		//Test for Pair
		Hand PA = new Hand();
		PA.addCard(new Card(Card.CardRankEnum.DEUCE,Card.CardSuitEnum.SPADES));
		PA.addCard(new Card(Card.CardRankEnum.TEN,Card.CardSuitEnum.HEARTS));
		PA.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.SPADES));
		PA.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.DIAMONDS));
		PA.addCard(new Card(Card.CardRankEnum.SEVEN,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 2 3 10 7 2 0: ");
		printArray(PA.determineHandRanking());
		
		//Test for High Card
		Hand BULL = new Hand();
		BULL.addCard(new Card(Card.CardRankEnum.DEUCE,Card.CardSuitEnum.SPADES));
		BULL.addCard(new Card(Card.CardRankEnum.TEN,Card.CardSuitEnum.HEARTS));
		BULL.addCard(new Card(Card.CardRankEnum.THREE,Card.CardSuitEnum.SPADES));
		BULL.addCard(new Card(Card.CardRankEnum.QUEEN,Card.CardSuitEnum.DIAMONDS));
		BULL.addCard(new Card(Card.CardRankEnum.JACK,Card.CardSuitEnum.SPADES));
		System.out.print("Should be 1 12 11 10 3 2: ");
		printArray(BULL.determineHandRanking());
	}
	
	public static void printArray(int[] ranking) {
		for(int i=0;i<6;i++)
		{
			System.out.print(ranking[i]+" ");
		}
		System.out.println("\n-------------------------------------------------");
	}
	
	/**
	 * Generates a random hand of 5 cards
	 * @return random hand generated
	 */
	public static Hand randomHand(){
		Deck deck = new Deck();
		Hand hand = new Hand();
		for(int i=0; i<5; i++){
			hand.addCard(deck.drawCard());
		}
		return hand;
	}

}
